package de.uni.kassel.campusappver3.crawler;

import java.util.regex.Matcher;

import de.uni.kassel.campusappver3.model.CrawlerReturnValue;

/**
 * crawls events from studentpartys.com that are at university at kassel
 * 
 * each event has a list like: { event name, event type, date , time}. keys are 0,1,2 ...
 * @see Crawler for iteration example
 * @author ckonze
 *
 */
public class UniEventsCrawler extends Crawler{

	public UniEventsCrawler(ICrawl listener) {
		super(listener);
	}

	@Override
	protected CrawlerReturnValue backgoundCrawl(Object[] params,
			CrawlerReturnValue crv) {
		int i = 0;
		Matcher urlMatcher = getUrlMatcher(
				"http://www.studentenpartys.com/?stadt=Kassel",
				"onmouseout(.*?)onmouseover");

		while (urlMatcher.find()) {
			Matcher event = getStringMatcher(urlMatcher.group(0),
					"title=\"(.*?)\"(.*?)\"(.*?)" +
					"width: 450px;\">(.*?), um (.*?) Uhr</div>");
			while (event.find()) {
				Matcher ort = getStringMatcher(event.group(0),"500px;\"><b>(.*?)</b></div>");
				ort.find();
				crv.appendValue("" + i, event.group(1));
				crv.appendValue("" + i, event.group(4));
				crv.appendValue("" + i, event.group(5));
				crv.appendValue("" + i, removeTagsEntitys(ort.group(0)).substring(9));
				i++;
			}
		}
		return crv;
	}

}
